<template>
  <div class="container">
    <el-form :model="editFormInfo" :rules="rules" ref="editFormInfo">
      <el-form-item label="学科名称" label-width="100px" prop="subjectName">
        <el-input v-model="editFormInfo.subjectName" placeholder="请输入学科名称"></el-input>
      </el-form-item>
      <el-form-item label="是否显示" label-width="100px">
        <el-switch v-model="editFormInfo.isFrontDisplay" active-color="#13ce66" inactive-color="#ff4949"> </el-switch>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align: right">
      <el-button @click="$emit('close')">取 消</el-button>
      <el-button type="primary" @click="editSubjects">确 定</el-button>
    </div>
  </div>
</template>

<script>
import { update } from '@/api/hmmm/subjects'
export default {
  name: 'subjectsEdit',
  props: {
    getid: {
      type: [Number, String, Object],
      require: true
    }
  },
  data() {
    return {
      editFormInfo: {
        subjectName: this.getid.subjectName, //学科名称
        isFrontDisplay: true, //是否在页面显示1是  0否
        id: this.getid.id
        // 存放id
      },
      //   校验
      rules: {
        subjectName: [{ required: true, message: '用户名不能为空', trigger: 'blur' }]
      }
    }
  },
  methods: {
    //   修改时间
    editSubjects() {
      this.$refs.editFormInfo.validate(async valid => {
        if (!valid) return
        try {
          // 发送请求
          this.isFrontDisplay = this.isFrontDisplay ? 1 : 0
          await update(this.editFormInfo)
          this.$message.success('修改成功')
          //   清空表单数据
          this.$refs.editFormInfo.resetFields()
          //   重新拉列表
          this.$emit('updateList')
          //   关闭弹框
          this.$emit('close')
        } catch (error) {
          console.dir(error)
          this.$message.error('修改失败，请重试')
        }
      })
    }
  }
}
</script>

<style scoped lang="less"></style>
